<?php

    include '../../lib/common/dbRoutines.php';
    include '../../lib/dao/WordDao.php';
	/*header('Content-type: text/html; charset=utf-8');*/
	
	$words = array();
	$table = '';
	
	$num = $_POST['num_words'];
	$complexity = $_POST['complexity'];
	$lang = $_POST['lang'];
    
	//$all_words = iconv("UTF-8", "windows-1251", $_POST['all_words']);
	$all_words = $_POST['all_words'];
	$temp = split("\n", $all_words);
		
	$words_in_use = array();
	foreach($temp as $key => $val){
		$words_in_use[$val] = 1;
	}	
	$conn = getDbConnection();  
	$wordDao = new WordDao($conn);  
	$words = $wordDao -> get_words($num, $complexity, &$words_in_use, $lang);
	
	$words_string = "";
	foreach($words as $key=>$val)
		$words_string = $words_string . "\n" . $key;
	
    if(count($words)==0){
        echo "no words";
    }
    else{
        echo $words_string;
    }
?>
